﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LDTB.Service;

namespace LDTB
{
    public partial class AddWard : Form
    {
        LDTBDataDataContext ds = DataService.DB;

        public AddWard()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           

            string wardName=txtWardName.Text.Trim();
         

            if(wardName==string.Empty){
                MessageBox.Show("Nhập tên huyện");
            }
            else { 
                
                //insert to db

                var ward = new Ward {WardName=wardName};
                ds.Wards.InsertOnSubmit(ward);
                ds.SubmitChanges();

                if (ward.ID != 0)
                {

                    MessageBox.Show("Đã thêm thành công");

                }
                else {

                    MessageBox.Show("Thêm thất bại");
                
                }
            
            }
        }

        private void AddWard_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
